package org.xtremeobjects.domain.model.expression.el;

import java.util.Properties;

import javax.el.ExpressionFactory;
import javax.el.ValueExpression;

import de.odysseus.el.ExpressionFactoryImpl;
import de.odysseus.el.util.SimpleContext;


public class ExpressionEvaluator  {

	public Object evaluate(Object obj, String expression) {
		Properties props = new Properties();
		props.put("javax.el.methodInvocations", "true");
		ExpressionFactory factory = new ExpressionFactoryImpl(props);
		SimpleContext context = new SimpleContext(new SimpleResolver());
		factory.createValueExpression(context, "#{self}", obj.getClass()).setValue(context, obj);
		ValueExpression expr2 = factory.createValueExpression(context, expression, Object.class);
		return expr2.getValue(context);
	}
	
}
